﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Xml;
using TomanuExtensions;
using TomanuExtensions.Utils;

namespace AmiEmuLib.AmigaConfiguration.DisplayConfig
{
    /// <summary>
    /// Windowed diaply settings.
    /// </summary>
    public class Window : XmlBase
    {
        /// <summary>
        /// Window rect position and size.
        /// </summary>
        public Rectangle WindowRect;

        /// <summary>
        /// Scale factor.
        /// </summary>
        public ScaleFactor ScaleFactor;

        /// <summary>
        /// Scaling mode. By factor, fot amiga to window or fit window to amiga.
        /// </summary>
        public WindowScalingMode Scaling;

        /// <summary>
        /// Ignore overscan borders.
        /// </summary>
        public bool IgnoreBorders;

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="a_reader"></param>
        public Window(XmlReader a_reader)
            : base(a_reader)
        {
        }

        protected override void ReadXml(XmlReader a_reader)
        {
            a_reader.ReadStartElement(GetType().Name);

            WindowRect = a_reader.ReadElementContentAsRectangle("WindowRect");
            ScaleFactor = a_reader.ReadElementContentAsEnum<ScaleFactor>("ScaleFactor");
            Scaling = a_reader.ReadElementContentAsEnum<WindowScalingMode>("Scaling");
            IgnoreBorders = a_reader.ReadElementContentAsBoolean("IgnoreBorders");

            a_reader.ReadEndElement();
        }

        public override void WriteXml(XmlWriter a_writer)
        {
            a_writer.WriteStartElement(GetType().Name);

            a_writer.WriteElementRectangle("WindowRect", WindowRect);
            a_writer.WriteElement("ScaleFactor", ScaleFactor);
            a_writer.WriteElement("Scaling", Scaling);
            a_writer.WriteElement("IgnoreBorders", IgnoreBorders);

            a_writer.WriteEndElement();
        }
    }
}
